package edu.pw.p2pclient.networking.webservice;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class ActiveRequest {
	private String mResName;
	private int mDistance;
	private double mLatitude;
	private double mLongitude;
	private int mNetwork;

	public ActiveRequest(String resName, int distance, double latitude,
			double longitude, int network) {
		mResName = resName;
		mDistance = distance;
		mLatitude = latitude;
		mLongitude = longitude;
		mNetwork = network;
	}

	public String getResName() {
		return mResName;
	}

	public int getDistance() {
		return mDistance;
	}

	public double getLatitude() {
		return mLatitude;
	}

	public double getLongitude() {
		return mLongitude;
	}

	public int getNetwork() {
		return mNetwork;
	}

	public final static JsonDeserializer<ActiveRequest> deserializer = new JsonDeserializer<ActiveRequest>() {

		@Override
		public ActiveRequest deserialize(JsonElement json, Type typeOfT,
				JsonDeserializationContext context) throws JsonParseException {

			String name = json.getAsJsonObject().get("name").getAsString();
			int distance = json.getAsJsonObject().get("distance").getAsInt();
			double latitude = json.getAsJsonObject().get("latitude")
					.getAsDouble();
			double longitude = json.getAsJsonObject().get("longitude")
					.getAsDouble();
			int network = json.getAsJsonObject().get("network").getAsInt();

			return new ActiveRequest(name, distance, latitude, longitude,
					network);
		}
	};
}
